Absolute X Relative links - #60
Conversation
- added argument `$absolute = true` to `LinkGeneratorInterface` and `FileInfoInterface` - added unit tests
📝 WalkthroughWalkthroughThe PR extends the image storage library's link generation system to support both absolute and relative URL generation. An Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FileInfo
participant LinkGenerator
participant SrcSetGenerator
participant ArgsFacade
Client->>FileInfo: srcSet(descriptor, absolute: true)
FileInfo->>LinkGenerator: srcSet(info, descriptor, absolute: true)
LinkGenerator->>SrcSetGenerator: generate(descriptor, pathInfo, absolute: true)
SrcSetGenerator->>ArgsFacade: createLink(absolute: true)
ArgsFacade->>LinkGenerator: link(pathInfo, absolute: true)
LinkGenerator-->>ArgsFacade: absolute URL
ArgsFacade-->>SrcSetGenerator: cache key (abs::...)
SrcSetGenerator-->>LinkGenerator: SrcSet
LinkGenerator-->>FileInfo: SrcSet
FileInfo-->>Client: SrcSet (absolute paths)
Client->>FileInfo: srcSet(descriptor, absolute: false)
FileInfo->>LinkGenerator: srcSet(info, descriptor, absolute: false)
LinkGenerator->>SrcSetGenerator: generate(descriptor, pathInfo, absolute: false)
SrcSetGenerator->>ArgsFacade: createLink(absolute: false)
ArgsFacade->>LinkGenerator: link(pathInfo, absolute: false)
LinkGenerator-->>ArgsFacade: relative URL
ArgsFacade-->>SrcSetGenerator: cache key (rel::...)
SrcSetGenerator-->>LinkGenerator: SrcSet
LinkGenerator-->>FileInfo: SrcSet
FileInfo-->>Client: SrcSet (relative paths)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Responsive/SrcSetGeneratorTest.phpt (1)
200-226:assertFacadePropertiesRelativeduplicatesassertFacadePropertiesalmost entirely.The two helpers differ only in
Assert::truevsAssert::falseon$facade->absolute. Consider collapsing them into a single parameterized helper:♻️ Suggested refactor
- private function assertFacadeProperties(ArgsFacade $facade, LinkGeneratorInterface $linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface $pathInfo): void - { - call_user_func(Closure::bind( - static function () use ($facade, $linkGenerator, $modifierFacade, $pathInfo): void { - Assert::same($facade->linkGenerator, $linkGenerator); - Assert::same($facade->modifierFacade, $modifierFacade); - Assert::same($facade->pathInfo, $pathInfo); - Assert::true($facade->absolute); - }, - null, - ArgsFacade::class, - )); - } - - private function assertFacadePropertiesRelative(ArgsFacade $facade, LinkGeneratorInterface $linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface $pathInfo): void - { - call_user_func(Closure::bind( - static function () use ($facade, $linkGenerator, $modifierFacade, $pathInfo): void { - Assert::same($facade->linkGenerator, $linkGenerator); - Assert::same($facade->modifierFacade, $modifierFacade); - Assert::same($facade->pathInfo, $pathInfo); - Assert::false($facade->absolute); - }, - null, - ArgsFacade::class, - )); - } + private function assertFacadeProperties( + ArgsFacade $facade, + LinkGeneratorInterface $linkGenerator, + ModifierFacadeInterface $modifierFacade, + PathInfoInterface $pathInfo, + bool $absolute = true, + ): void { + call_user_func(Closure::bind( + static function () use ($facade, $linkGenerator, $modifierFacade, $pathInfo, $absolute): void { + Assert::same($facade->linkGenerator, $linkGenerator); + Assert::same($facade->modifierFacade, $modifierFacade); + Assert::same($facade->pathInfo, $pathInfo); + Assert::same($absolute, $facade->absolute); + }, + null, + ArgsFacade::class, + )); + }Then update the call sites:
- $this->assertFacadePropertiesRelative($facade, $linkGenerator, $modifierFacade, $pathInfo); + $this->assertFacadeProperties($facade, $linkGenerator, $modifierFacade, $pathInfo, false);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Responsive/SrcSetGeneratorTest.phpt` around lines 200 - 226, The two duplicate test helpers assertFacadeProperties and assertFacadePropertiesRelative should be collapsed into a single parameterized helper (e.g., assertFacadeProperties(ArgsFacade $facade, LinkGeneratorInterface $linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface $pathInfo, bool $expectedAbsolute)) that performs the three Assert::same checks on $facade->linkGenerator, $facade->modifierFacade and $facade->pathInfo and then asserts $facade->absolute equals $expectedAbsolute (use Assert::true when $expectedAbsolute is true, Assert::false when false, or a single equality/assertSame on the boolean). Replace all callers of assertFacadePropertiesRelative to call the new helper with expectedAbsolute = false and existing callers of assertFacadeProperties with expectedAbsolute = true, then remove the now-unused duplicate method.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/Responsive/SrcSetGeneratorTest.phpt`:
- Around line 200-226: The two duplicate test helpers assertFacadeProperties and
assertFacadePropertiesRelative should be collapsed into a single parameterized
helper (e.g., assertFacadeProperties(ArgsFacade $facade, LinkGeneratorInterface
$linkGenerator, ModifierFacadeInterface $modifierFacade, PathInfoInterface
$pathInfo, bool $expectedAbsolute)) that performs the three Assert::same checks
on $facade->linkGenerator, $facade->modifierFacade and $facade->pathInfo and
then asserts $facade->absolute equals $expectedAbsolute (use Assert::true when
$expectedAbsolute is true, Assert::false when false, or a single
equality/assertSame on the boolean). Replace all callers of
assertFacadePropertiesRelative to call the new helper with expectedAbsolute =
false and existing callers of assertFacadeProperties with expectedAbsolute =
true, then remove the now-unused duplicate method.
Summary by CodeRabbit
New Features
Chores